package ru.paswd.marketprice.utils

object StringUtils {
    fun decodeParams(params: String?): Map<String, String> {
        if (params == null) {
            return mapOf()
        }

        val map = mutableMapOf<String, String>()
        val paramSets = params.split("&")

        paramSets.forEach { set ->
            val decodedSet = decodeSet(set)
            if (decodedSet != null) {
                map[decodedSet.first] = decodedSet.second
            }
        }

        return map
    }

    private fun decodeSet(set: String): Pair<String, String>? {
        val splitted = set.split("=")
        if (splitted.size < 2) {
            return null
        }

        return Pair(splitted[0], splitted[1])
    }
}